#!/bin/python

# program count parts of budget
# author: Kra53n
# data of creating: 06.06.20

from os import system as os_system
from time import sleep as time_sleep
from xerox import copy as xerox_copy
from sys import argv


### CONSTANTS
SPEED_TYPING = 0.15 # seconds


### FUNCTIONS
def clear():
    '''Function clear everything that was before in terminal
    '''
    os_system('clear')

def greeting():
    '''This function is write greeting
    '''
    word = 'B u d g e t  s c r i p t'
    for i in range(len(word) + 1):
        print(word[:i] + ' ')
        time_sleep(SPEED_TYPING)
        if i == len(word):
            input()
        clear()

def count(text, percent, num, next_step = 'n'):
    '''Function give final result for part
    percent - example: you put 20 it measne 20%
    '''
    percent = num * percent / 100
    string = '{} - {}\n'.format(text, percent)
    if next_step == 'y':
        return percent
    else:
        return string

def check_argvs():
    '''This function check argvs
    '''
    clipboard, money, total_money, telegram = 0, 0, 0, 0
    if '-c' in argv[1:]:
        clipboard = True
    if '-m' in argv[1:]:
        money = True
        total_money = argv[argv.index('-m')+1]
    if '-t' in argv[1:]:
        telegram = True
    return clipboard, money, total_money, telegram

def telegram_write(message):
    from telethon import TelegramClient
    message = 'Budget\n'.upper() + message
    api_id = 
    api_hash = 
    with TelegramClient('anon', api_id, api_hash) as client:
        client.loop.run_until_complete(client.send_message('me', message))


if __name__ == '__main__':
    '''
    50 percents on investition
    15 percents on goals
    30 percents on myself
    5 percents on charity

    Investition:
    50 percents on metal
    30 percents on currency
    20 percents on development

    '''
    clipboard, money, total_money, telegram = check_argvs()
    # ask user about information about money
    if money == True:
        TOTAL = float(total_money)
    else:
        greeting()
        TOTAL = float(input('Put your number: '))
    # create message that will print
    message = '\n'
    invest = count('ON INVESTITION', 50, TOTAL, 'y')
    message += count('On metal', 50, invest)
    message += count('On currency', 30, invest)
    message += count('On development', 20, invest)
    message += '\n'
    message += count('On goals', 15, TOTAL)
    message += count('On myself', 30, TOTAL)
    message += count('On charity', 5, TOTAL)
    if not telegram or not money:
        print(message)
    if telegram:
        from sys import exit
        telegram_write(message)
        if money:
            exit()
    # take message to clipboard
    if clipboard == True:
        xerox_copy(message)
    input()
